package net.steam.easyjoboa.biz.impl;

import java.util.List;

import net.steam.easyjoboa.biz.ClaimVoucherBiz;
import net.steam.easyjoboa.dao.ClaimVoucherDao;
import net.steam.easyjoboa.entity.ClaimVoucher;

public class ClaimVoucherBizImpl implements ClaimVoucherBiz{

	private ClaimVoucherDao claimDao;
	
	public ClaimVoucherDao getClaimDao() {
		return claimDao;
	}
	public void setClaimDao(ClaimVoucherDao claimDao) {
		this.claimDao = claimDao;
	}

	/**
	 * 添加
	 */
	public Integer addClaim(ClaimVoucher claim) {
		int rows=0;
		try {
			rows=claimDao.addEntity(claim);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return rows;
	}
	
	/**
	 * 查找未审批报销单, 即status=0
	 */
	public List<ClaimVoucher> getAllClaimVouchers(Integer userId) {
		String hql=String.format("from ClaimVoucher cv where cv.status=0 and cv.employee.userId !=%s",userId);
		return claimDao.find(hql);
	}
	
	/**
	 * 报销审核-批量更新状态
	 */
	public void updateClaim(ClaimVoucher claim) {
		claimDao.updateEntity(claim);
	}
	
	/**
	 * 根据id查找
	 */
	public ClaimVoucher getClaimById(Integer id) {
		return claimDao.findById(id);
	}
	
	/**
	 * 查找个人报销单
	 * @return
	 */
	public List<ClaimVoucher> getClaimByUser(Integer userId) {
		String hql=String.format("from ClaimVoucher cv where cv.employee.userId=%s order by cv.cvId desc",userId);
		return claimDao.find(hql);
	}

}
